var fs = require("fs");
var util = require("util");

function hr(msg){
    console.log("------------ " + msg + " ------------\n");
}

function end(data){
    console.log("---> Result:\n " + data);
    console.log("\n------------ end ------------\n");    
}

hr("Start");
var data = fs.readFileSync("test01.txt");
end(data);

hr("open file");
var f01 = fs.openSync("test01.txt", "rs");
end(f01.toString());

hr("file stat");
var stat = fs.statSync("test01.txt");
console.log("is file: " + stat.isFile());
console.log("is Dir: " + stat.isDirectory());
console.log("is FIFO: " + stat.isFIFO());
end(util.inspect(stat, true, null, true));


hr("read dir");
var dir = fs.readdirSync("./");
for(let f in dir){
    console.log(dir[f]);
}

try{
    fs.rmdirSync("./test");    
}catch(err){
    console.log(new Error("No such a directory").message);
}

var dir = fs.readdirSync("./");
for(let f in dir){
    console.log(dir[f]);
}